﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using SoftwareConsulting.BI11.Studio.Core.DBProviders;
using SoftwareConsulting.BI11.Studio.Core.Project;
using SoftwareConsulting.BI11.Studio.Core.Project.Metadata;
using SoftwareConsulting.BI11.Studio.BasicEntities;
using SoftwareConsulting.BI11.Studio.Core.Project.SituationsHierarchy;
using SoftwareConsulting.BI11.Studio.ProcessWait;
using SoftwareConsulting.Interfaces.BasicEntities;
using SoftwareConsulting.BI11.Studio.UI.ProjectExplorer.TimeSeries;
using SoftwareConsulting.BI11.Studio.InternalServices;
using SoftwareConsulting.BI11.Studio.UI.Properties;

namespace SoftwareConsulting.BI11.Studio.UI.ProjectExplorer
{
    public partial class DataExtractionDialog : RestorableForm
    {        
        private bool _programCombosUpdate;//флаг программного обновления комбиков привязок
        private IMetadataObject _destinationObject;//объект, в который хотели бы загрузить данные
        private ProjectDescriptor _projectLink;//для связи с проектом
        private List<string> _sourceColumnNames; //строки привязок        
        private Excel _excel; //класс для работы с экселем
        private string _fileName; //файл, откуда производим загрузку
        private int _failedRow; //строка файла, где произошла ошибка
        private int _failedColumn; //колонка файла, где произошла ошибка

        private static int GetFailedColumn(char needchar)
        {
            return char.ConvertToUtf32(needchar.ToString(CultureInfo.CurrentCulture), 0) - char.ConvertToUtf32('A'.ToString(CultureInfo.CurrentCulture), 0) + 1;
        }

        /// <summary>
        /// Актуализирует информацию о выбранной странице
        /// </summary>
        private void ReadFieldsFromSheet()
        {
            _excel.OpenWorksheetByIndex(SheetBox.SelectedIndex);
            //читаем верхнюю строку
            bool halt = false;
            _sourceColumnNames.Clear();            
            int i = 1;
            while (i <= 26)            
            {
                char letter = (char)((int)'A' + i - 1);
                //try
                {
                    _sourceColumnNames.Add(i.ToString(CultureInfo.CurrentCulture) + " - " + _excel.GetValue(letter + StartRowBox.Value.ToString(CultureInfo.CurrentCulture)));
                }
                /*не знаю какое именно исключение здесь надо ловить поэтому пока комменчу(чтоб узнать тип эксепшена) catch
                {                    
                    if (i == 0)
                    {
                        GeneralMethods.ShowUserError(Resources.BI_EXCEPTION_LOADDATA_EXCEL_NO_COLS);
                        halt = true;
                    }                    
                    break;
                }*/
                i++;
            }                                        
            //обновляем комбики привязок
            int c = BindingsGrid.Rows.Count;
            for (int j = 0; j < c; j++)
            {
                DataGridViewRow row = BindingsGrid.Rows[j];
                DataGridViewComboBoxCell combo = row.Cells[1] as DataGridViewComboBoxCell;
                DataGridViewComboBoxCell.ObjectCollection items = combo.Items;
                items.Clear();
                if ((_destinationObject.Kind != MetadataObjectKind.Cube) || (j < (c - 1)))                
                {
                    //это не <значение> куба, значит можно оставить непривязанным
                    items.Add(Constants.NullDoesNotMatterString);
                }
                if (!halt)
                {
                    items.AddRange(_sourceColumnNames.ToArray());
                }
                combo.Value = combo.Items[0];                
            }            
            OKButton.Enabled = !halt;
        }

        /// <summary>
        /// Обновляет информацию о прогрессе загрузки
        /// </summary>
        /// <param name="rowIndex"></param>
        /// <remarks>строка -1 => скрыть информацию о прогрессе</remarks>
        private void UpdateProgress(int rowIndex)
        {            
            LoadProgress.Refresh();
            string s = LoadProgressLabel.Text;
            s = s.Substring(0, s.IndexOf("#", StringComparison.CurrentCulture) + 1) + rowIndex.ToString(CultureInfo.CurrentCulture) + s.Substring(s.IndexOf(")", StringComparison.CurrentCulture));
            LoadProgressLabel.Text = s;
            if (rowIndex == -1)
            {
                LoadProgressLabel.Visible = false;
                LoadProgress.Visible = false;
            }
            else
            {
                if (!LoadProgress.Visible)
                {                    
                    LoadProgress.Visible = true;
                    LoadProgressLabel.Visible = true;
                }
            }
        }

        private struct FieldInfo
        {
            private char _fChar;
            private string _decimalSeparator;
            private string _typestring;

            public char ColumnChar
            {
                get
                {
                    return _fChar;
                }
                set
                {
                    _fChar = value;
                }
            }

            public string DecimalSeparator
            {
                get
                {
                    return _decimalSeparator;
                }
                set
                {
                    _decimalSeparator = value;
                }
            }

            public string TypeString
            {
                get
                {
                    return _typestring;
                }
                set
                {
                    _typestring = value;
                }
            }
        }

        /// <summary>
        /// Производит импорт данных
        /// </summary>
        /// <returns>true - успешно, false - нет</returns>
        private bool DoImport()        
        {
            UpdateProgress(0);
            INamedList binds = new NamedList();
            ITable tab = _destinationObject as ITable;
            IDateAndFactCorrelations updatingDAFCobject = _destinationObject as IDateAndFactCorrelations;
            string caldimlabel = string.Empty;
            if ((updatingDAFCobject != null) && (updatingDAFCobject.GetCalendarDimension() != null))            
            {
                caldimlabel = updatingDAFCobject.GetCalendarDimension().Label;
            }
            for (int j = 0; j < BindingsGrid.Rows.Count; j++)
            {
                DataGridViewRow row = BindingsGrid.Rows[j];
                string fname = row.Cells[0].Value as string;
                var combo = row.Cells[1] as DataGridViewComboBoxCell;
                int cindex = combo.Items.IndexOf(combo.Value);
                char cChar = 'A';
                if ((cindex != 0) || (fname == Resources.BI_LOADDATA_CUBE_VALUE))                
                {
                    //есть привязка
                    int shift = fname == Resources.BI_LOADDATA_CUBE_VALUE ? 0 : 1;
                    cChar = (char)((int)'A' + cindex - shift);
                    FieldInfo fInfo = new FieldInfo()
                    {
                        ColumnChar = cChar
                    };
                    combo = row.Cells[2] as DataGridViewComboBoxCell;
                    if (combo.Items.Count > 0)
                    {
                        string sepstring = row.Cells[2].Value as string;
                        fInfo.DecimalSeparator = sepstring[sepstring.Length - 1].ToString(CultureInfo.CurrentCulture);
                    }
                    if (tab != null)
                    {
                        fInfo.TypeString = tab.GetColumnProperties(fname).ColumnType.ToString();
                    }
                    else
                    {
                        if (fname == Resources.BI_LOADDATA_CUBE_VALUE)
                        {
                            fInfo.TypeString = "System.Double";
                        }
                        else
                        {
                            ICalendarDimension calDim = updatingDAFCobject.GetCalendarDimension();
                            if ((calDim == null)||(calDim.Label!=fname))                            
                            {
                                fInfo.TypeString = "System.String";
                            }
                            else
                            {                                
                                fInfo.TypeString = "System.DateTime";                                
                            }
                        }
                    }
                    binds.AddValue(fname, fInfo);
                }                
            }            
            int wKey = -1;
            Hashtable dims = new Hashtable();
            if (updatingDAFCobject != null)
            {
                wKey = (int)(_projectLink.RepositoryLink.WorldsDimension.Items.GetItemByPosition(WorldBox.SelectedIndex).Tag);
                foreach(KeyValuePair<string,object> entry in binds)
                {
                    if (entry.Key != Resources.BI_LOADDATA_CUBE_VALUE)
                    {
                        IFactsDimension fdim = _projectLink.RepositoryLink.GetObjectDescriptorByLabel(entry.Key, MetadataObjectKind.Dimension) as IFactsDimension;
                        if (fdim != null)
                        {                            
                            dims.Add(entry.Key, fdim);
                        }
                    }
                }
            }
            Hashtable cashedDimItemsTags = new Hashtable();
            int startRow = Convert.ToInt32(CaptionsRowCheckBox.Checked ? StartRowBox.Value + 1 : StartRowBox.Value);
            int i = startRow;
            while (_failedRow == -1)
            {
                UpdateProgress(i);
                INamedList rowvals = new NamedList();
                int k = -1;
                foreach(KeyValuePair<string,object> entry in binds)
                {
                    k++;
                    string fieldName = entry.Key;
                    FieldInfo finfo = (FieldInfo)(entry.Value);
                    char needchar = finfo.ColumnChar;
                    string str = string.Empty;
                    //try
                    {
                        str = _excel.GetValue(needchar + i.ToString(CultureInfo.CurrentCulture));
                    }
                    /*не знаю че здесь ловить надо, наверное ничего catch
                    {                        
                        if (i == startRow)
                        {
                            _failedRow = i;
                            _failedColumn = k;
                            break;
                        }                        
                    }                    */
                    CultureInfo ci = CultureInfo.CurrentUICulture;                    
                    switch (finfo.TypeString)
                    {                          
                        case "System.Int32":
                            int h_int = -1;                            
                            if (int.TryParse(str, NumberStyles.Any, ci, out h_int))
                            {
                                rowvals.AddValue(fieldName, h_int);
                            }
                            else
                            {
                                _failedRow = i;
                                _failedColumn = GetFailedColumn(needchar);
                            }
                            break;
                        case "System.Boolean":
                            bool h_bool = false;                            
                            if (bool.TryParse(str, out h_bool))
                            {
                                rowvals.AddValue(fieldName, h_bool);
                            }                            
                            else
                            {
                                _failedRow = i;
                                _failedColumn = GetFailedColumn(needchar);
                            }
                            break;
                        case "System.Double":
                            double h_double = -1.0;
                            CultureInfo ci2 = new CultureInfo(ci.Name);
                            ci2.NumberFormat.NumberDecimalSeparator = ((FieldInfo)(entry.Value)).DecimalSeparator;
                            if (double.TryParse(str, NumberStyles.Float, ci2, out h_double))
                            {
                                rowvals.AddValue(fieldName, h_double);
                            }
                            else
                            {
                                _failedRow = i;
                                _failedColumn = GetFailedColumn(needchar);
                            }
                            break;
                        case "System.String":
                            if (!string.IsNullOrEmpty(str))
                            {
                                rowvals.AddValue(fieldName, str);
                            }
                            break;
                        case "System.DateTime":
                            DateTime h_datetime = Constants.NullDate; 
                            if (DateTime.TryParseExact(str, DateFormatBox.Text, ci, DateTimeStyles.AllowWhiteSpaces, out h_datetime))
                            {
                                rowvals.AddValue(fieldName, h_datetime);
                            }
                            else
                            {
                                _failedRow = i;
                                _failedColumn = GetFailedColumn(needchar);
                            }
                            break;                            
                    }                                        
                }
                if (rowvals.Count == 0)
                {
                    _failedRow = -1;
                    break;
                }
                if (_failedRow != -1)
                {
                    continue;
                }                
                if (tab != null)
                {
                    try
                    {
                        tab.AddRow(rowvals);
                    }
                    catch (BITableDuplicateRowException)
                    {
                        //дубликаты просто не надо вставлять
                    }
                }
                else
                {                    
                    DateTime dt = Constants.NullDate;
                    List<DimensionItem> dimitems = new List<DimensionItem>();
                    double val = Constants.NullDouble;                    
                    foreach(KeyValuePair<string,object> entry in rowvals)
                    {                        
                        if (caldimlabel == entry.Key)
                        {
                            dt = (DateTime)(entry.Value);
                            continue;
                        }
                        if (entry.Key == Resources.BI_LOADDATA_CUBE_VALUE)
                        {
                            val = (double)(entry.Value);
                            continue;
                        }
                        object cashed = cashedDimItemsTags[entry.Key + "_" + (entry.Value as string)];
                        if (cashed != null)
                        {
                            dimitems.Add(new DimensionItem(entry.Key, (int)cashed));
                        }
                        else
                        {
                            IFactsDimension fdim = dims[entry.Key] as IFactsDimension;
                            INamedHierarchy<INamed> h = fdim.Items.GetItemsByName(entry.Value as string, true);
                            if (h.ItemsCount == 1)
                            {
                                cashed = h.GetItemByPosition(0).Tag;
                                cashedDimItemsTags.Add(entry.Key + "_" + (entry.Value as string), cashed);
                                dimitems.Add(new DimensionItem(fdim.Label, cashed));
                            }
                            else
                            {
                                ///таких элементов измерения либо
                                ///несколько, либо вообще нет; и в
                                ///том, и в другом случае ничего
                                ///не поделать - надо аварийно
                                ///завершать импорт
                                _failedRow = i;
                                int colindex = char.ConvertToUtf32(((char)(binds.GetValue(fdim.Label))).ToString(CultureInfo.CurrentCulture), 0) - char.ConvertToUtf32("A", 0) + 1;
                                _failedColumn = colindex;
                            }
                        }                        
                        if (_failedRow != -1)
                            break;
                    }
                    if (_failedRow == -1)
                    {
                        try
                        {
                            if (dimitems.Count > 0)
                            {
                                (updatingDAFCobject as ICube).WriteValue(dimitems, dt, wKey, val);
                            }
                            else
                            {
                                updatingDAFCobject.WriteValue(dt, wKey, val);
                            }
                        }
                        catch (BICalendarDimensionNoDateException ex)
                        {
                            GeneralMethods.ShowUserError(ex.Message);
                            _failedRow = i;
                            int colindex = char.ConvertToUtf32(((FieldInfo)(binds.GetValue(updatingDAFCobject.GetCalendarDimension().Label))).ColumnChar.ToString(CultureInfo.CurrentCulture), 0) - char.ConvertToUtf32("A", 0) + 1;
                            _failedColumn = colindex;
                        }
                    }
                }
                i++;
            }            
            UpdateProgress(-1);
            if (_failedRow != -1)
            {
                GeneralMethods.ShowUserError(Resources.BI_LOADDATA_ERROR_FAILED + " (" + Resources.BI_LOADDATA_STRING + " " + _failedRow.ToString(CultureInfo.CurrentCulture) + ", " + Resources.BI_LOADDATA_COLUMN + " " + _failedColumn.ToString(CultureInfo.CurrentCulture) + ")");
                return false;
            }
            Processing.WellDone();
            return true;
        }

        /// <summary>
        /// Обновляет пример даты
        /// </summary>
        private void RefreshDateSample()
        {
            DateSampleBox.Text = DateTime.Now.ToString(DateFormatBox.Text,CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Обновляет комбики привязок
        /// </summary>
        private void UpdateBindingCombos()
        {
            string headerstring = string.Empty;
            switch (DestinationTypeBox.SelectedIndex)
            {
                case 0:
                    //таблица
                    _destinationObject = _projectLink.RepositoryLink.GetObjectDescriptorByLabel(DestinationBox.SelectedItem as string, MetadataObjectKind.Table).Bind();
                    headerstring = Resources.BI_LOADDATA_OBJECTENTITY_FIELD;
                    break;
                case 1:
                    //куб
                    _destinationObject = _projectLink.RepositoryLink.GetObjectDescriptorByLabel(DestinationBox.SelectedItem as string, MetadataObjectKind.Cube).Bind();
                    headerstring = Resources.BI_LOADDATA_OBJECTENTITY_DIMENSION;
                    break;
                case 2:
                    //временной ряд
                    _destinationObject = _projectLink.RepositoryLink.GetObjectDescriptorByLabel(DestinationBox.SelectedItem as string, MetadataObjectKind.TimeSeries).Bind();
                    ITimeSeries series = _destinationObject as ITimeSeries;
                    SelectActiveCalculationDialog sacd = new SelectActiveCalculationDialog(_projectLink, series);
                    if (sacd.ShowDialog() == DialogResult.OK)
                    {
                        series.ActiveCalculation = sacd.ActiveCalculation;
                    }
                    else
                        Close();
                    headerstring = Resources.BI_LOADDATA_OBJECTENTITY_DIMENSION;
                    break;
            }                   
            BindingsGrid.Columns[0].HeaderText = headerstring;
            DataGridViewRowCollection rows = BindingsGrid.Rows;            
            rows.Clear();
            switch (_destinationObject.Kind)
            {
                case MetadataObjectKind.Table:
                    ITable tab = _destinationObject as ITable;
                    ICollection<string> cnames = tab.GetColumnNames();
                    foreach(string cname in cnames)
                    {
                        object[] cols = new object[3];
                        cols[0] = cname;
                        rows.Add(cols);
                        if (tab.GetColumnProperties(cname).ColumnType == typeof(double))
                        {
                            DataGridViewComboBoxCell combo = rows[rows.Count - 1].Cells[2] as DataGridViewComboBoxCell;
                            combo.Items.Clear();
                            combo.Items.Add(Resources.BI_LOADDATA_DECIMALSEPARATOR + ",");
                            combo.Items.Add(Resources.BI_LOADDATA_DECIMALSEPARATOR + ".");
                            combo.Value = combo.Items[0];
                        }
                    }
                    break;
                case MetadataObjectKind.TimeSeries:
                case MetadataObjectKind.Cube:
                    IDateAndFactCorrelations updatingDAFCobject = _destinationObject as IDateAndFactCorrelations;
                    if (updatingDAFCobject.GetCalendarDimension() != null)
                    {
                        object[] cols = new object[3];
                        cols[0] = updatingDAFCobject.GetCalendarDimension().Label;
                        rows.Add(cols);
                    }
                    int c = updatingDAFCobject.GetFactsDimensionsCount();
                    Guid wdimid = _projectLink.RepositoryLink.WorldsDimension.Id;
                    for (int i = 0; i < c; i++)
                    {
                        object[] cols = new object[3];
                        Guid fdimid = updatingDAFCobject.GetFactsDimensionByPosition(i).Id;
                        if (fdimid != wdimid)
                        {
                            cols[0] = fdimid;
                            rows.Add(cols);
                        }
                    }
                    //значение
                    {
                        object[] cols = new object[3];
                        cols[0] = Resources.BI_LOADDATA_CUBE_VALUE;
                        rows.Add(cols);
                        DataGridViewComboBoxCell combo = rows[rows.Count - 1].Cells[2] as DataGridViewComboBoxCell;
                        combo.Items.Clear();
                        combo.Items.Add(Resources.BI_LOADDATA_DECIMALSEPARATOR + ",");
                        combo.Items.Add(Resources.BI_LOADDATA_DECIMALSEPARATOR + ".");
                        combo.Value = combo.Items[0];
                    }
                    break;
            }
            ReadFieldsFromSheet();
        }

        /// <summary>
        /// Обрабатывает смену типа приемника
        /// </summary>
        private void ApplyDestinationTypeChange()
        {
            ComboBox.ObjectCollection dests = DestinationBox.Items;
            dests.Clear();
            switch(DestinationTypeBox.SelectedIndex)
            {
                case 0:
                    //таблица                    
                    foreach(MetadataObjectDescriptor info in _projectLink.RepositoryLink.GetObjectsDescriptors(MetadataObjectKind.Table))
                    {                        
                        dests.Add(info.Label);
                    }
                    WorldBox.Items.Clear();
                    WorldBox.Enabled = false;
                    break;
                case 1:
                    //куб                    
                    foreach(MetadataObjectDescriptor info in _projectLink.RepositoryLink.GetObjectsDescriptors(MetadataObjectKind.Cube))
                    {                        
                        dests.Add(info.Label);
                    }                    
                    ComboBox.ObjectCollection items = WorldBox.Items;
                    items.Clear();
                    IFactsDimension wdim = _projectLink.RepositoryLink.WorldsDimension;
                    int c = wdim.Items.ItemsCount;
                    for (int i = 0; i < c; i++)
                    {
                        items.Add(wdim.Items.GetItemByPosition(i).Name);
                    }
                    WorldBox.SelectedIndex = 0;
                    WorldBox.Enabled = true;
                    break;
                case 2:
                    //временной ряд                    
                    foreach(MetadataObjectDescriptor info in _projectLink.RepositoryLink.GetObjectsDescriptors(MetadataObjectKind.TimeSeries))
                    {                        
                        dests.Add(info.Label);
                    }
                    ComboBox.ObjectCollection items2 = WorldBox.Items;
                    items2.Clear();
                    IFactsDimension wdim2 = _projectLink.RepositoryLink.WorldsDimension;
                    int c2 = wdim2.Items.ItemsCount;
                    for (int i = 0; i < c2; i++)
                    {
                        items2.Add(wdim2.Items.GetItemByPosition(i).Name);
                    }
                    WorldBox.SelectedIndex = 0;
                    WorldBox.Enabled = true;
                    break;
            }
        }

        /// <summary>
        /// Инициализация диалога загрузки
        /// </summary>
        private void Initialize()
        {            
            _programCombosUpdate = false;
            _failedRow = -1;
            _failedColumn = -1;
            _sourceColumnNames = new List<string>();
            SourceBox.Text = _fileName;
            SourceTypeBox.SelectedIndex = 0;
            if (_destinationObject == null)
            {
                DestinationTypeBox.SelectedIndex = 0;
            }
            else
            {
                DestinationTypeBox.SelectedIndex = _destinationObject.Kind == MetadataObjectKind.Table ? 0 : 1;
            }
            _excel = new Excel();
            _excel.OpenDocument(_fileName);            
            List<string> sheetsNames = _excel.WorksheetsNames;
            ComboBox.ObjectCollection sheetsItems = SheetBox.Items;
            sheetsItems.Clear();
            int c = sheetsNames.Count;
            if (c > 0)
            {                
                ComboBox.ObjectCollection formatsItems = DateFormatBox.Items;
                formatsItems.Clear();                
                for (int i = 0; i < MetadataSharedMethods.DateFormatsCount; i++)
                {
                    formatsItems.Add(MetadataSharedMethods.GetDateTimeFormatByIndex(i));
                }
                DateFormatBox.SelectedIndex = 0;
                //создаем комбики привязок                
                _programCombosUpdate = true;
                for (int i = 0; i < c; i++)
                {
                    sheetsItems.Add(sheetsNames[i]);
                }                
                if (_destinationObject == null)
                {
                    DestinationBox.SelectedIndex = 0;
                    switch(DestinationTypeBox.SelectedIndex)
                    {
                        case 0:
                            //таблица
                            _destinationObject = _projectLink.RepositoryLink.GetObjectDescriptorByLabel(DestinationBox.SelectedItem as string, MetadataObjectKind.Table).Bind();
                            break;
                        case 1:
                            //куб
                            _destinationObject = _projectLink.RepositoryLink.GetObjectDescriptorByLabel(DestinationBox.SelectedItem as string, MetadataObjectKind.Cube).Bind();
                            break;
                        case 2:
                            //временной ряд
                            _destinationObject = _projectLink.RepositoryLink.GetObjectDescriptorByLabel(DestinationBox.SelectedItem as string, MetadataObjectKind.TimeSeries).Bind();
                            break;
                    }
                }
                else
                {
                    DestinationBox.SelectedItem = _destinationObject.Label;
                }            
                SheetBox.SelectedIndex = c - 1;
                _programCombosUpdate = false;
                UpdateBindingCombos();
            }
            else
            {
                BindingsGroupBox.Enabled = false;
                OKButton.Enabled = false;
                GeneralMethods.ShowUserError(Resources.BI_LOADDATA_ERROR_EXCEL_NOSHEETS);
            }
        }

        public DataExtractionDialog(ProjectDescriptor currentProject, string fileName, IMetadataObject destinationObject)
        {
            _destinationObject = destinationObject;
            _projectLink = currentProject;
            _fileName = fileName;
            InitializeComponent();
        }

        private void LoadDataDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_failedRow != -1)
            {
                _failedRow = -1;
                _failedColumn = -1;
                e.Cancel = true;
            }
            else
            {
                if (_excel != null)
                {
                    _excel.Dispose();
                    _excel = null;
                }
            }
        }

        private void SheetBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_programCombosUpdate)
            {
                ReadFieldsFromSheet();
            }
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            DoImport();
        }

        private void DateFormatBox_TextUpdate(object sender, EventArgs e)
        {
            RefreshDateSample();            
        }

        private void DateFormatBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            RefreshDateSample();
        }

        private void DestinationBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_programCombosUpdate)
            {
                UpdateBindingCombos();
            }
        }

        private void DestinationTypeBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ApplyDestinationTypeChange();
        }

        private void DataExtractionDialog_Load(object sender, EventArgs e)
        {
            Initialize();
        }
    }
}
